package model

// RetOk 一切OK的返回码
const RetOk = "0"

// CodeOk 一切OK的CODE
const CodeOk = "00000"

// MsgOk 一切OK的消息
const MsgOk = "ok"

type Result struct {
	Api     string      `json:"api,omitempty"`
	Code    string      `json:"code,omitempty"`
	ErrCode string      `json:"err_code,omitempty"`
	Msg     string      `json:"msg,omitempty"`
	Data    interface{} `json:"data,omitempty"`
}

func (l Result) TestFail() bool {
	return l.Code != RetOk
}

func Ok() *Result {
	return &Result{Code: RetOk, ErrCode: CodeOk, Msg: MsgOk}
}

func OkData(data any) *Result {
	result := Ok()
	result.Data = data
	return result
}

func Fail(code string, errCode string, msg string) *Result {
	return &Result{Code: code, ErrCode: errCode, Msg: msg}
}

func FailData(code string, errCode string, msg string, data any) *Result {
	result := Fail(code, errCode, msg)
	result.Data = data
	return result
}
